﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UtilZ.Dotnet.Ex.Config;

namespace UtilZ.Tool.WatchdogPlugin
{
    [ConfigRoot("WatchdogConfig")]
    public class WatchdogConfig : IConfig
    {
        private long _monitiorCheckMillisecondsInterval = 500L;
        /// <summary>
        /// 进程监视检查间隔
        /// </summary>
        [ConfigItem("MonitiorCheckMillisecondsInterval", "进程监视检查间隔,单位/毫秒.小于等于0使用默认值500")]
        public long MonitiorCheckMillisecondsInterval
        {
            get { return _monitiorCheckMillisecondsInterval; }
            set
            {
                if (value <= 0)
                {
                    _monitiorCheckMillisecondsInterval = 500;
                }
                else
                {
                    _monitiorCheckMillisecondsInterval = value;
                }
            }
        }

        ///// <summary>
        ///// 主机查询程序名称
        ///// </summary>
        //[ConfigItem("HostQueryAppName", "主机查询程序名称")]
        //public string HostQueryAppName { get; set; } = @"HostQuery\UtilZ.Tool.HostQuery.exe";

        ///// <summary>
        ///// 主机查询端口
        ///// </summary>
        //[ConfigItem("HostQueryPort", "主机查询端口")]
        //public int HostQueryPort { get; set; } = 5300;

        private int _noRespondingMillisecondsTimeout = 5000;
        /// <summary>
        /// 未响应时长
        /// </summary>
        [ConfigItem("NoRespondingMillisecondsTimeout", "未响应时长,单位/毫秒.小于等于0使用默认值5000")]
        public int NoRespondingMillisecondsTimeout
        {
            get { return _noRespondingMillisecondsTimeout; }
            set
            {
                if (value <= 0)
                {
                    _noRespondingMillisecondsTimeout = 5000;
                }
                else
                {
                    _noRespondingMillisecondsTimeout = value;
                }
            }
        }

        /// <summary>
        /// 心跳数据收发端口
        /// </summary>
        [ConfigItem("HeartPort", "心跳数据收发端口")]
        public int HeartPort { get; set; } = 5301;

        private int _heartCheckSecondsTimeout = 5;
        /// <summary>
        /// 心跳检测超时时长,单位/秒
        /// </summary>
        [ConfigItem("HeartCheckSecondsTimeout", "心跳检测超时时长,单位/秒.小于等于0使用默认值5")]
        public int HeartCheckSecondsTimeout
        {
            get { return _heartCheckSecondsTimeout; }
            set
            {
                if (value <= 0)
                {
                    _heartCheckSecondsTimeout = 5;
                }
                else
                {
                    _heartCheckSecondsTimeout = value;
                }
            }
        }



        #region single instance
        private readonly static WatchdogConfig _inctance;
        public static WatchdogConfig Instance
        {
            get { return _inctance; }
        }

        static WatchdogConfig()
        {
            _inctance = ConfigHelper.Load<WatchdogConfig>("WatchdogConfig.xml");
        }
        #endregion




        /// <summary>
        /// 
        /// </summary>
        public WatchdogConfig()
            : base()
        {

        }

        /// <summary>
        /// 
        /// </summary>
        public void InitDefaultValue()
        {

        }
    }
}
